package com.lzh.persevere.controller;

import com.lzh.persevere.common.R;
import com.lzh.persevere.common.ResultUtil;
import com.lzh.persevere.model.entity.Role;
import com.lzh.persevere.model.qo.PageModelQO;
import com.lzh.persevere.model.ro.IdRO;
import com.lzh.persevere.model.ro.role.EditRoleRO;
import com.lzh.persevere.model.vo.role.RoleMenuInfoVO;
import com.lzh.persevere.service.RoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;
import java.util.Map;

/**
 * 角色controller
 *
 * @author luzhiheng
 * @since 2025-07-29
 */
@Api(tags = "角色")
@RestController
@RequestMapping("/role")
public class RoleController {

    @Resource
    private RoleService roleService;

    @ApiOperation(value = "查询角色列表")
    @PostMapping("/findRoleList")
    public R<List<Role>> findRoleList() {
        List<Role> roleList = roleService.list();
        return ResultUtil.success(roleList);
    }

    @ApiOperation(value = "分页查询角色列表")
    @PostMapping("/findRolePage")
    public R<Map<String, Object>> findRolePage(@Valid @RequestBody PageModelQO qo) {
        return ResultUtil.success(roleService.pageList(qo));
    }

    @ApiOperation(value = "编辑角色")
    @PostMapping("/editRole")
    public R<Boolean> editUserInfo(@Valid @RequestBody EditRoleRO ro) {
        return ResultUtil.success(roleService.editRole(ro));
    }

    @ApiOperation(value = "新增角色")
    @PostMapping("/addRole")
    public R<Boolean> addRole(@Valid @RequestBody Role ro) {
        return ResultUtil.success(roleService.save(ro));
    }

    @ApiOperation(value = "删除角色")
    @PostMapping("/deleteRole")
    public R<Boolean> deleteRole(@Valid @RequestBody IdRO ro) {
        return ResultUtil.success(roleService.deleteRole(ro.getId()));
    }

    @ApiOperation(value = "查询角色权限信息列表")
    @PostMapping("/findRoleMenuList")
    public R<RoleMenuInfoVO> findRoleMenuList(@Valid @RequestBody IdRO ro) {
        return ResultUtil.success(roleService.findRoleMenuList(ro.getId()));
    }

}
